package com.da.javatest.niuke.baodian;

/**
 * @author chenlida
 * @date 2020/10/3 23:18
 * https://www.nowcoder.com/practice/9618c2a9e8a14c3e82954ee14168f592?tpId=8&&tqId=10994&rp=1&
 * ru=/ta/cracking-the-coding-interview&qru=/ta/cracking-the-coding-interview/question-ranking
 */
public class C1Different {
    public static void main(String[] args) {
        System.out.println(checkDifferent("aeiou"));
        System.out.println(checkDifferent("BarackObama"));
    }

    public static boolean checkDifferent(String iniString) {
        if (iniString.length() == 1 || iniString.length() == 0) {
            return true;
        }
        if (iniString.length() > 256) {
            return false;
        }
        char[] chars = iniString.toCharArray();
        int length = chars.length;
        for (int i = 0; i < length; i++) {
            char c1 = chars[i];
            // 每一个位置都从当前位置的下一个位置进行判断 因为前面的已经判断过 不许重复判断
            for (int j = i + 1; j < length; j++) {
                char c2 = chars[j];
                if (c1 == c2) {
                    return false;
                }
            }
        }
        return true;
    }
}
